﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace Inspired.Euler
{
    public static class Problem042
    {
        static void Main()
        {
            Regex.Matches(File.ReadAllText(@"..\..\Data\words.txt"), @"""(?<name>.*?)"",?")
                .OfType<Match>()
                .Where(m => m.Groups["name"].Value.IsTriangleWord())
                .Count()
                .DisplayAndPause();
        }

        static bool IsTriangleWord(this string word)
        {
            int i = 1;
            int triangle = 0;
            int value = word.Aggregate(0, (seed, c) => seed + ((int)c) - 64);
            while (triangle < value)
            {
                triangle += i++;
            }
            return triangle == value;
        }
    }
}
